package chenji.gunapi.antiCheat;

import java.util.HashMap;

import org.bukkit.entity.Player;

import chenji.gunapi.GunAPI;
import chenji.gunapi.task.Taskable;

public class AntiMouseCheatManager implements Taskable{
	public AntiMouseCheatManager(){
		GunAPI.getGunAPI().getGunTaskManager().registerPerSecondTask(this);
	}
	private HashMap<Player, Integer> protectLeft = new HashMap<>();
	private HashMap<Player, Integer> protectRight = new HashMap<>();

	public void logEvent(Player p, boolean isLeft) {
		if (isLeft) {
			if (this.protectLeft.containsKey(p)) {
				this.protectLeft.put(p, this.protectLeft.get(p) + 1);
			} else {
				this.protectLeft.put(p, 1);
			}
		} else {
			if (this.protectRight.containsKey(p)) {
				this.protectRight.put(p, this.protectRight.get(p) + 1);
			} else {
				this.protectRight.put(p, 1);
			}
		}
	}

	@Override
	public void task() {
		for (Player p : this.protectLeft.keySet()) {
			if (this.protectLeft.get(p) >= 21) {
				p.kickPlayer("§c发包速度过快");
			}
		}
		this.protectLeft.clear();
		for (Player p : this.protectRight.keySet()) {
			if (this.protectRight.get(p) >= 21) {
				p.kickPlayer("§c发包速度过快");
			}
		}
		this.protectRight.clear();
	}
}
